{include file="public/header" /}
<div class="container mtb-15">
	<form action="" style="background: #FFF;padding: 15px;border-radius: 3px;width: 800px;margin: auto;" {$info['ask_id'] ? '' : 'is-cache-data="true"'}>
		<div class="form-group" style="position: relative;">
			<input class="form-control search-question" autocomplete="off" type="text" name="title" value="{$info['title']}" placeholder="描述您的问题">
			<div class="form-list ajax-question-box">
			</div>
		</div>
		<div class="form-group">
			<textarea class="summernote_editor" id="summernote_editor" name="content" placeholder="对问题进行补充描述(可选)" style="width: 100%">{$info['content']}</textarea>
		</div>
		<div class="form-group">{:widget('Widget/category_select', ['话题', 'category_id', $info['category_id'], 'ask_index', '', 0, 0])}</div>
		<div class="form-group">
			{$info['reward'] > 0 ? '已悬赏' : ''}
			{gt name="info.reward" value="0"}
				<span class="reward">{$info['reward']}</span>
			{/gt}
			{gt name="reward_usable" value="0"}
				{$info['reward'] > 0 ? '追加悬赏' : '悬赏'}
				<select name="reward">
					{volist name="reward_list" id="reward"}
						{elt name=":trim($reward)" value="$reward_usable"}
							<option value="{$reward}">{$reward}</option>
						{/elt}
					{/volist}
				</select>
				豆子
			{/gt}
			<label><input type="checkbox" name="is_anonymous" value="1" {$info['is_anonymous'] == 1 ? 'checked' : ''}>匿名发布</label>
		</div>
		<div class="form-group text-center">
			<button type="submit" class="btn btn-danger">发布问题</button>
		</div>
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		$('.search-question').bind('input propertychange', function() {  
		    var str = $(this).val();  
		    	str = $.trim(str);
        	var str_temp = str.replace(/[\u4e00-\u9fa5]/g, 'aa')//将汉字替换为aa 
        	if(str_temp.length >= 3){
        		$.ajax({
        			url: "{:url('Question/ajax_search')}",
        			data: {'title': $(this).val()},
        			type: 'post',
        			dataType: 'json',
        			success: function(json){
        				if(json.code == 1){
        					$(".ajax-question-box").show();
        					$(".ajax-question-box").html('');
        					var html = '';
        					$.each(json.data.list, function(index){
        						html += '<div class="list-item"><a href="' + json.data.list[index]['url']  + '">' + json.data.list[index]['title'] + ' <span>' + json.data.list[index]['answer_num'] + ' 回答</span></a></div>';
        					})
        					$(".ajax-question-box").append(html);
        					$(document).one("click", function(){
						        $(".ajax-question-box").hide();
						    });
        				}
        			}
        		});
        	}else{
        		$(".ajax-question-box").hide();
        	}
		}); 
	});
</script>
{include file="public/footer" /}